//
//  WBEmotionTool.m
//  WeiBo
//
//  Created by EDZ on 2017/9/28.
//  Copyright © 2017年 powertorque. All rights reserved.
//

#import "WBEmotionTool.h"

#import "BSEmotionModel.h"

/// 默认表情
static NSArray<BSEmotionSmallPicture *> *_defaultEmotions;
/// 浪小花表情
static NSArray<BSEmotionSmallPicture *> *_lxhEmotions;

@implementation WBEmotionTool

+ (NSArray<BSEmotionSmallPicture *> *)defaultEmotions
{
    if (_defaultEmotions == nil) {
        NSString *plist = [[NSBundle mainBundle] pathForResource:kDefaultEmotionLocalPlistDirectory ofType:nil];
        _defaultEmotions = [BSEmotionSmallPicture mj_objectArrayWithFile:plist];
        for (BSEmotionSmallPicture *smallPicture in _defaultEmotions) {
            smallPicture.directory = kDefaultEmotionLocalImageDirectory;
            smallPicture.smallImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@/%@", smallPicture.directory, smallPicture.png]];
        }
    }
    return _defaultEmotions;
}

+ (NSArray<BSEmotionSmallPicture *> *)lxhEmotions
{
    if (_lxhEmotions) {
        NSString *plist = [[NSBundle mainBundle] pathForResource:kLxhEmotionLocalPlistDirectory ofType:nil];
        _defaultEmotions = [BSEmotionSmallPicture mj_objectArrayWithFile:plist];
        for (BSEmotionSmallPicture *smallPicture in _defaultEmotions) {
            smallPicture.directory = kLxhEmotionLocalImageDirectory;
            smallPicture.smallImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@/%@", smallPicture.directory, smallPicture.png]];
        }
    }
    return _lxhEmotions;
}

+ (BSEmotionSmallPicture *)baseEmotionSmallPictureWithDes:(NSString *)desString
{
    __block BSEmotionSmallPicture *smallPicture = nil;
    
    // 从默认图片中找
    [[self defaultEmotions] enumerateObjectsUsingBlock:^(BSEmotionSmallPicture * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.chs isEqualToString:desString] || [obj.cht isEqualToString:desString]) {
            smallPicture = obj;
            *stop = YES;
        }
    }];
    
    if (smallPicture) return smallPicture;
    
    // 从浪小花表情中找
    [[self lxhEmotions] enumerateObjectsUsingBlock:^(BSEmotionSmallPicture * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj.chs isEqualToString:desString] || [obj.cht isEqualToString:desString]) {
            smallPicture = obj;
            *stop = YES;
        }
    }];
    
    return smallPicture;
}

@end
